Talk:Run-time type information
This article is rated Start-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||||||
|
The contents of the typeid page were merged into Run-time type information. For the contribution history and old versions of the redirected page, please see its history; for the discussion at that location, see its talk page. |
The contents of the dynamic_cast page were merged into Run-time type information. For the contribution history and old versions of the redirected page, please see its history; for the discussion at that location, see its talk page. |
- I vote to keep the entry separate. I believe that the theme allows for a more comprehensive text, and if it is merged, it would probably remain as it is.
I too oppose
- Oppose too, it'd be hidden if it were merged, makes more sense on its own. EAi 16:38, 27 October 2005 (UTC)
- Oppose —R. Koot 20:12, 25 November 2005 (UTC)
Code example
[edit]Provided code example won't compile with g++ (4.0.2). Compilation produces "source type is not polymorphic" error. Adding virtual destructor to the base class solves the problem.--Iwasz 21:59, 21 March 2006 (UTC)
- It compiles fine as of today with a recent g++ and clang++. Mlkj (talk) 22:34, 31 December 2015 (UTC)
Only objects/classes?
[edit]Currently, the article states:
- In programming, RTTI [...] means keeping information about an object's data type in memory at runtime
Isn't it more correct to say:
- In programming, RTTI [...] means keeping information about an entity's data type in memory at runtime
as runtime information can be kept for simple data types such as integers, too? --Abdull (talk) 12:04, 9 February 2008 (UTC)
- The variable article says variable has as synonyms object and identifier. Yet, I think there is the possibility of confusion with OOP objects. --Abdull (talk) 12:09, 9 February 2008 (UTC)
Why is this identified as a C++ thing?
[edit]Delphi has had RTTI since the very beginning, and it's integrated into the language and used throughout the runtime, unlike C++ where it was bolted on after the fact and is a special option that has to be enabled. —Preceding unsigned comment added by 69.46.35.146 (talk) 21:14, 22 April 2009 (UTC)
I concur. Run-time type information (in the non-Proper Noun sense) is a feature that is available in all reflective languages, of which there are MANY. The term "Reflection" is virtually identical in meaning to RTTI but is much more accepted academically. Either this article should be merged with Reflection (computer programming), or it should document the other languages such as Delphi and D Programming Language that also refer specifically to "RTTI" as a proper noun, or perhaps this page should just be expunged as it is currently just a piece of technical information specific to C++, which makes it completely irrelevant to encyclopedia readers. --118.90.128.222 (talk) 11:53, 20 August 2009 (UTC)
- If RTTI is use also in other languages than C++, there should be parallel code examples wherever C++ code appears. Sae1962 (talk) 08:29, 26 January 2011 (UTC)
The funny thing is that RTTI in other languages (Delphi, C#) is way better integrated and yet this article gives an impression that this is a C++ thing. — Preceding unsigned comment added by 84.43.121.62 (talk) 11:40, 9 October 2018 (UTC)
The whole article describes RTTI as a C++ feature, then out of nowhere, for a single sentence it mentions Java cast besides dynamic_cast. This is very confusing for someone not familiar with the topic. --A Tejesember (talk) 17:56, 18 July 2019 (UTC)
- The article used to be more general in its wording. This was changed by an anonymous editor in 2008, I think (see diff). – Tea2min (talk) 10:53, 19 July 2019 (UTC)
Ada also has run-time typing information: Ada Core OOP4.31.13.17 (talk) 18:41, 12 July 2021 (UTC)
I will try to make this article more general. I think RTTI deserves an article, the issue is that, as it stands today, it's too focused on C++. BernardoSulzbach (talk) 16:38, 13 July 2021 (UTC)
RTTI in C++ is only available for polymorphic types
[edit]Run-time type information in C++ is only available for polymorphic types. Please see [expr.dynamic.cast] and [expr.typeid] in the C++20 standard. For example, an attempt to down-cast a pointer to an instance of a non-polymorphic class A
down to a pointer to an instance of a non-polymorphic cass B
derived from A
is ill-formed:
class A {}; class B : public A {}; int main() { A* a = new B; B* b = dynamic_cast<B*>(a); // ill-formed! }
An up-cast would compile and would work as expected, using only static information.
Similarly, [expr.typeid] says: "When typeid is applied to an expression other than a glvalue of a polymorphic class type, the result refers to a std::type_info object representing the static type of the expression." I.e., it does compile, but the result does not (and in fact cannot) represent the dynamic type of the expression. – Tea2min (talk) 19:03, 14 July 2021 (UTC)
- Thank you, and sorry for the undue revert. You are correct that actual RTTI will only be available for polymorphic types, regardless of typeid being defined or not. BernardoSulzbach (talk) 20:06, 14 July 2021 (UTC)